home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / tcp / wu_ftpd_37_21.lha / wu-ftpd / src / strsep.c < prev    next >
C/C++ Source or Header  |  1994-04-01  |  2KB  |  67 lines

  1. /*-
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that: (1) source distributions retain this entire copyright
  7.  * notice and comment, and (2) distributions including binaries display
  8.  * the following acknowledgement:  ``This product includes software
  9.  * developed by the University of California, Berkeley and its contributors''
  10.  * in the documentation or other materials provided with the distribution
  11.  * and in all advertising materials mentioning features or use of this
  12.  * software. Neither the name of the University nor the names of its
  13.  * contributors may be used to endorse or promote products derived
  14.  * from this software without specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  */
  19.  
  20. #include <string.h>
  21. #include <stdio.h>
  22.  
  23. #if defined(LIBC_SCCS) && !defined(lint)
  24. static const char sccsid[] = "@(#)strsep.c    5.3 (Berkeley) 5/18/90";
  25.  
  26. #endif /* LIBC_SCCS and not lint */
  27.  
  28. /*
  29.  * Get next token from string *stringp, where tokens are nonempty
  30.  * strings separated by characters from delim.
  31.  *
  32.  * Writes NULs into the string at *stringp to end tokens.
  33.  * delim need not remain constant from call to call.
  34.  * On return, *stringp points past the last NUL written (if there might
  35.  * be further tokens), or is NULL (if there are definitely no more tokens).
  36.  *
  37.  * If *stringp is NULL, strtoken returns NULL.
  38.  */
  39. char *
  40. strsep(register char **stringp, register char *delim)
  41.   /* const */
  42. {
  43.     register char *s;
  44.     register /* const */ char *spanp;
  45.     register int c,
  46.       sc;
  47.     char *tok;
  48.  
  49.     if ((s = *stringp) == NULL)
  50.         return (NULL);
  51.     for (tok = s;;) {
  52.         c = *s++;
  53.         spanp = delim;
  54.         do {
  55.             if ((sc = *spanp++) == c) {
  56.                 if (c == 0)
  57.                     s = NULL;
  58.                 else
  59.                     s[-1] = 0;
  60.                 *stringp = s;
  61.                 return (tok);
  62.             }
  63.         } while (sc != 0);
  64.     }
  65.     /* NOTREACHED */
  66. }
  67.